from typing import List

from aiogram.utils.keyboard import InlineKeyboardBuilder, ReplyKeyboardBuilder

from mytypes import KB_Item
from utils import log


@log.catch
def generate_inline_keyboard(items: List[KB_Item], adjust_in: int = 3):
    kb = InlineKeyboardBuilder()

    for item in items:
        kb.button(text=item.text, callback_data=item.cb_data.pack() if item.cb_data else "")

    kb.adjust(adjust_in)

    return kb.as_markup()

@log.catch
def generate_form_keyboard(labels: str | list[str]):
    if isinstance(labels, str):
        labels = [labels]
                
    kb = ReplyKeyboardBuilder()

    [kb.button(text=label) for label in labels]

    return kb.as_markup(resize_keyboard=True, one_time_keyboard=True)
